import request from '@/utils/request'

//标签类别树
export function getLabelSelectTree() {
  return request({
    url: '/material/label/labelTreeSelect',
    method: 'get'
  })
}

// 查询文件记录-2列表
export function listFlie(query) {
  return request({
    url: '/file/flie/list_pcode',
    method: 'get',
    params: query
  })
}

// 查询文件记录详细
export function getFlie(id) {
  return request({
    url: '/file/flie/' + id,
    method: 'get'

  })
}
// 查询标记文件记录详细
export function getTableFlie(id) {
  return request({
    url: '/file/flie/table/' + id,
    method: 'get'
  })
}
// 新增文件记录
export function addFlie(data) {
  return request({
    url: '/file/flie',
    method: 'post',
    data: data
  })
}

//目录树
export function getSelectTree() {
  return request({
    url: '/file/flie/treeselect',
    method: 'get'
  })
}

// 汇总信息
export function getTotal() {
  return request({
    url: '/file/flie/total_info',
    method: 'get'
  })
}
//创建文件夹
export function addFolder(data) {

  console.log(data);
  console.log("addFolder");
  return request({
    url: '/file/flie/create_folder',
    method: 'post',
    data: data
  })
}

// 修改文件记录
export function updateFlie(data,param) {
  return request({
    url: '/file/flie',
    method: 'put',
    data: data,
    params:param
  })
}

// 删除文件记录-2
export function delFlie(id) {
  return request({
    url: '/file/flie/' + id,
    method: 'delete'
  })
}




// 导出文件记录-2
export function exportFlie(query) {
  return request({
    url: '/file/flie/export',
    method: 'get',
    params: query
  })
}
  // 目录树的调用


// 下载文件
export function downFile(downloadObject) {
  return request({
    url: '/common/download',
    data: downloadObject,
    method: 'get'
  })
}

  export function downloadFlie(fileId) {
    return request({
      url: '/file/flie/downloadFile/'+fileId,
      method: 'post',
      responseType:'blob'
    })
  }


// export function down(id){
//   return request({
//     url:'/file/upload/down/'+id,
//     method:'get',
//     responseType:'blob'
//   })
// }

//转化标记文件yolo数值为坐标值
export function transferYolo(yoloData1, yoloData2, yoloData3, yoloData4, dw, dh) {
  let center_x = Math.round(yoloData1 * dw)
  let center_y = Math.round(yoloData2 * dh)
  let bbox_width = Math.round(yoloData3 * dw)
  let bbox_height = Math.round(yoloData4 * dh)
  let xmin = (center_x - bbox_width) / 2;
  let ymin = (center_y - bbox_height) / 2
  let xmax = (center_x + bbox_width) / 2;
  let ymax = (center_y + bbox_height) / 2
  let x0 = center_x - Math.abs(xmax - xmin) / 2;
  let y0 = center_y - Math.abs(ymax - ymin) / 2;
  let info = {
    "x0": x0,
    "y0": y0,
    "w": Math.abs(xmax - xmin),
    "h": Math.abs(ymax - ymin)
  };
  return info
}
